package com.zimin.mapper.injector.method;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import lombok.SneakyThrows;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.scripting.defaults.RawSqlSource;

/**
 * @author zimin
 * @since 2022/1/19 11:20 上午
 */
public class SelectById extends AbstractMethod {

    @SneakyThrows
    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
//        SqlMethod sqlMethod = "SELECT %s FROM %s WHERE %s=#{%s} %s";
        var sqlSource = new RawSqlSource(this.configuration,
                String.format("SELECT %s FROM %s WHERE %s=#{%s} %s",
                        super.sqlSelectColumns(tableInfo, Boolean.FALSE),
                        tableInfo.getTableName(),
                        tableInfo.getKeyColumn(),
                        tableInfo.getKeyProperty(),
                        tableInfo.getLogicDeleteSql(Boolean.TRUE, Boolean.TRUE)),
                Object.class);
        Class<?> aClass = Class.forName("com.zimin.cloud.mine.pojo.system.view.AccountVO");
        return super.addSelectMappedStatementForOther(mapperClass, "selectById1", sqlSource, aClass);
    }

}
